<template>
	<el-dialog title="信息互通对话框" v-model="visible" :width="600" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="消息标题" prop="subject">
				<el-input v-model="form.subject" placeholder="消息标题" rows="4"></el-input>
			</el-form-item>
			<el-form-item label="接收组织" prop="toOrgId">
				<el-select v-model="form.toOrgId" multiple placeholder="请选择" style="width: 100%">
					<el-option
						v-for="item in otherOrgList"
						:key="item.value"
						:label="item.label"
						:value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="消息内容" prop="content">
				<el-input type="textarea" v-model="form.content" placeholder="消息内容" rows="4"></el-input>
			</el-form-item>
			<el-form-item label="相关附件" prop="attachId">
				<sc-upload-file :apiObj="apiObj" v-model="fileList" :data="{module:'email'}" :showFileList="false" @success="addNewFile">
					<el-button type="primary" icon="el-icon-upload">上传附件</el-button>
				</sc-upload-file>
				<attach-menu v-model:attachIds="form.attachId" :roleFlag="4" :preview="true"></attach-menu>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">发 送</el-button>
		</template>
	</el-dialog>

</template>
<script>
import AttachMenu from "@/views/module/attachMenu";

export default {
	emits: ['success', 'closed'],
	components: {
		AttachMenu
	},
	props:{
		otherOrgList:Object
	},
	data() {
		return {
			dialog: {
				isShow: false
			},
			visible: false,
			isSaveing: false,
			isShowMsg: false,
			form: {
				subject:'',
				toOrgId: '',
				content:'',
				attachId:''
			},
			fileList:[],
			apiObj:this.$API.file.attach.uploadFile,
			rules: {
				subject: [
					{required: true, message: '消息标题不能为空', trigger: 'blur'}
				],
				toOrgId: [
					{required: true, message: '请选择消息接收人员', trigger: 'blur'}
				],
				content:[
					{required: true, message: '消息内容不能为空', trigger: 'blur'}
				]
			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = await this.$API.email.sendEmailForwardRecord.post(this.form);
					if (res.code == 200) {
						this.isSaveing = false;
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		addNewFile(res, file)
		{
			let tArr =[];
			if(this.form.attachId!=undefined&&this.form.attachId!=null&&this.form.attachId!=''){
				tArr = this.form.attachId.split(",");
			}
			tArr.push(res.data.attachId);
			this.form.attachId = tArr.join(",");
		},
	}
}
</script>

<style>
</style>
